#! /bin/sh
# Reload Miredo when an interface comes up

set -e

# Don't bother to reload when lo is configured.
if [ "$IFACE" = lo ]; then
	exit 0
fi

# Only run from ifup.
if [ "$MODE" != start ]; then
	exit 0
fi

# Miredo only cares about inet and inet6. Get thee gone, strange people
# still using ipx.
#if [ "$ADDRFAM" != inet ]; then
#	exit 0
#fi

# Actually, due to this bug - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=475188
# we need to do things differently. Exclude ipx instead (and IPv6; Miredo runs on IPv4).
if [ "${ADDRFAM}" = "ipx" ] || [ "${ADDRFAM}" = "inet6" ]; then
	exit 0
fi

# Is /usr mounted?
if [ ! -e /usr/sbin/miredo ]; then
	exit 0
fi

# Is the miredo service running?
if [ ! -f /var/run/miredo.pid ] || \
   [ "$(ps -p "$(cat /var/run/miredo.pid)" -o comm=)" != miredo ]; then
	exit 0
fi

invoke-rc.d miredo reload --quiet

exit 0

